package lessons5;

import tool.CmdControl;

/**
 * 注册检测功能
 */
public class lessons5_4 {
    public static void main(String[] args) {
        User user = new User();
        boolean isRuning = true;
        while(isRuning){
            System.out.println("输入用户名:");
            String name = CmdControl.in();
            System.out.println("输入密码:");
            String password = CmdControl.in();
        try {
            user.enrool(name, password);
            isRuning = false;
        } catch (Exception e) {
            // TODO: handle exception
            System.out.println("错误信息:"+e.toString());
        }
        }
    }
}

class User{
    private String name,passWord;

    public void enrool(String name,String passWord) throws Exception
    {
        if(name==null||passWord==null||name.isEmpty()||passWord.isEmpty())
            throw new Exception("用户名和密码不能为空");

        if(name.length()<3||name.length()>10)
            throw new Exception("用户名长度为3--10个字符");

        if(passWord.length()<8||passWord.length()>10)
            throw new Exception("密码长度为8--10个字符");

        System.out.println("用户名:"+name+" 密码:"+passWord+" 注册完成");
        this.name = name;
        this.passWord = passWord;
    }
}